home *** CD-ROM | disk | FTP | other *** search
- /*
- * Copyright (c) 1996 Sun Microsystems, Inc. All Rights Reserved.
- *
- * Permission to use, copy, modify, and distribute this software
- * and its documentation for NON-COMMERCIAL purposes and without
- * fee is hereby granted provided that this copyright notice
- * appears in all copies. Please refer to the file "LICENSE"
- * for further important copyright and licensing information.
- *
- * SUN MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF
- * THE SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
- * TO THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
- * PARTICULAR PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR
- * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
- * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES.
- *
- * THIS SOFTWARE IS NOT DESIGNED OR INTENDED FOR USE OR RESALE AS ON-LINE
- * CONTROL EQUIPMENT IN HAZARDOUS ENVIRONMENTS REQUIRING FAIL-SAFE
- * PERFORMANCE, SUCH AS IN THE OPERATION OF NUCLEAR FACILITIES, AIRCRAFT
- * NAVIGATION OR COMMUNICATION SYSTEMS, AIR TRAFFIC CONTROL, DIRECT LIFE
- * SUPPORT MACHINES, OR WEAPONS SYSTEMS, IN WHICH THE FAILURE OF THE
- * SOFTWARE COULD LEAD DIRECTLY TO DEATH, PERSONAL INJURY, OR SEVERE
- * PHYSICAL OR ENVIRONMENTAL DAMAGE ("HIGH RISK ACTIVITIES"). SUN
- * SPECIFICALLY DISCLAIMS ANY EXPRESS OR IMPLIED WARRANTY OF FITNESS FOR
- * HIGH RISK ACTIVITIES.
- */
-
- package java.sql;
-
- /**
- * <P>This class is a thin wrapper around java.util.Date that allows
- * JDBC to identify this as a SQL DATE value. It adds formatting and
- * parsing operations to support the JDBC escape syntax for date
- * values.
- */
- public class Date extends java.util.Date {
-
- /**
- * Construct a Date
- *
- * @param year year-1900
- * @param month 0 to 11
- * @param day 1 to 31
- */
- public Date(int year, int month, int day) {
- super(year, month, day);
- }
-
- /**
- * Construct a Date using a milliseconds time value
- *
- * @param date milliseconds since January 1, 1970, 00:00:00 GMT
- */
- public Date(long date) {
- // If the millisecond date value contains time info, mask it out.
- super(date);
- int year = getYear();
- int month = getMonth();
- int day = getDate();
- super.setTime(0);
- setYear(year);
- setMonth(month);
- setDate(day);
- }
-
- /**
- * Set a Date using a milliseconds time value
- *
- * @param date milliseconds since January 1, 1970, 00:00:00 GMT
- */
- public void setTime(long date) {
- // If the millisecond date value contains time info, mask it out.
- super.setTime(date);
- int year = getYear();
- int month = getMonth();
- int day = getDate();
- super.setTime(0);
- setYear(year);
- setMonth(month);
- setDate(day);
- }
-
- /**
- * Convert a string in JDBC date escape format to a Date value
- *
- * @param s date in format "yyyy-mm-dd"
- * @return corresponding Date
- */
- public static Date valueOf(String s) {
- int year;
- int month;
- int day;
- int firstDash;
- int secondDash;
-
- if (s == null) throw new java.lang.IllegalArgumentException();
-
- firstDash = s.indexOf('-');
- secondDash = s.indexOf('-', firstDash+1);
- if ((firstDash > 0) & (secondDash > 0) & (secondDash < s.length()-1)) {
- year = Integer.parseInt(s.substring(0, firstDash)) - 1900;
- month = Integer.parseInt(s.substring(firstDash+1, secondDash)) - 1;
- day = Integer.parseInt(s.substring(secondDash+1));
- } else {
- throw new java.lang.IllegalArgumentException();
- }
-
- return new Date(year, month, day);
- }
-
- /**
- * Format a date in JDBC date escape format
- *
- * @return a String in yyyy-mm-dd format
- */
- public String toString () {
- int year = super.getYear() + 1900;
- int month = super.getMonth() + 1;
- int day = super.getDate();
- String yearString;
- String monthString;
- String dayString;
-
-
- yearString = Integer.toString(year);
-
- if (month < 10) {
- monthString = "0" + month;
- } else {
- monthString = Integer.toString(month);
- }
-
- if (day < 10) {
- dayString = "0" + day;
- } else {
- dayString = Integer.toString(day);
- }
-
- return ( yearString + "-" + monthString + "-" + dayString);
- }
-
- // Override all the time operations inherited from java.util.Date;
- public int getHours() {
- throw new java.lang.IllegalArgumentException();
- }
-
- public int getMinutes() {
- throw new java.lang.IllegalArgumentException();
- }
-
- public int getSeconds() {
- throw new java.lang.IllegalArgumentException();
- }
-
- public void setHours(int i) {
- throw new java.lang.IllegalArgumentException();
- }
-
- public void setMinutes(int i) {
- throw new java.lang.IllegalArgumentException();
- }
-
- public void setSeconds(int i) {
- throw new java.lang.IllegalArgumentException();
- }
-
- }
-
-